package com.example.demo.algorithm.test;

import com.example.demo.algorithm.graph.DepthFirstSearch;
import com.example.demo.algorithm.graph.Graph;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * @Author: xiatian
 * @CreateTime: 2022/2/6 1:21 下午
 * @Description:
 */
public class Traffic_Project_Test2 {
    public static void main(String[] args) throws Exception {
        //构建一个缓冲读取流BufferedReader
        BufferedReader br = new BufferedReader(new InputStreamReader(Traffic_Project_Test2.class.getResourceAsStream("/static/traffic_project.txt")));
        //读取第一行数据20
        int totalCity = Integer.parseInt(br.readLine());
        //构建一个graph对象
        Graph g = new Graph(totalCity);
        //读取第二行数据7
        int roadNmuber = Integer.parseInt(br.readLine());
        //循环读取有限次，读取已经修建好的道路
        for (int i = 0; i < roadNmuber; i++) {
            String road = br.readLine();//"0 1"
            String[] str = road.split(" ");
            int v = Integer.parseInt(str[0]);
            int w = Integer.parseInt(str[1]);
            //调用图的addEdge方法，把边添加到图中，表示已经修建好的道路
            g.addEdge(v, w);
        }


        //构建一个深度优先搜索对象，起点设置为顶点9
        DepthFirstSearch search = new DepthFirstSearch(g, 9);
        //调用marked方法，判断8顶点和10顶点是否与起点9相通
        System.out.println("顶点8和顶点9是否相通：" + search.marked(8));
        System.out.println("顶点10和顶点9是否相通：" + search.marked(10));

    }
}
